package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "Servlet12", value = "/getReqInfo")
public class Servlet12 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //使用request获取以下的信息
        //获取本次请求的方法（Get/post）
        String method = request.getMethod();
        //获取本次请求的URI
        String uri = request.getRequestURI();
        //获取本次请求的参数
        String query = request.getQueryString();
        //获取本应用程序的名称（web02）
        String ctxPath = request.getContextPath();
        //获取当前服务器的主机名（localhost)
        String serverName = request.getServerName();
        //可以打印到控制台，可以打印客户端
        System.out.println(method);
        PrintWriter out = response.getWriter();//往客户端的输出流
        out.println(uri);
        out.println(query);
        out.println(ctxPath);
        out.println(serverName);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
